<template>
  <!-- 欠费用户明细 -->
  <div class="monitor-detials">
    <div class="search-group">
      <van-search left-icon="search" v-model="queryParams.deviceNum" :clearable="false" placeholder="请输入手机号" @search="handleSearch" />
      <div class="btn-search">
        筛选：
        <span class="btn-item" v-for="item in btnList" :key="item.label" :class="queryParams.userStatus == item.value ? 'active' : ''" @click="hadleBtn(item.value)">
          {{ item.label }}
        </span>
      </div>
    </div>
    <van-list
      v-model="loading"
      loading-text="加载中"
      :finished="finished"
      finished-text="没有更多了"
      @load="onload"
    >
    <div class="detail-info" v-for="(item,index) in list" :key="index">
      <img class="item-img-user" src="~@/assets/imgs/publicline/board/icon-users.png" />
      <div class="info-content">
        <div class="info-detail">
          <span class="info-name">{{ item.CUTOMER_NAME }}</span>
          <span class="info-flag">{{ item.DEVICE_NUMBER }}</span>
        </div>
        <div class="info-tc">
          <div class="info-desc">欠费金额<span>{{ item.OWE_FEE }}</span></div>
          <div class="info-desc">当期欠费<span>{{ item.TDQ_OWE_DQ }}</span></div>
          <div class="info-desc">联系方式<span>{{ item.CONTACT_PHONE }}</span></div>
          <div class="info-desc">用户状态<span>{{ item.USER_STATUS_P_DESC }}</span></div>
          <div class="info-desc">产品<span>{{ item.PRODUCT_ID_DESC }}</span></div>
          <div class="info-desc">停机时间<span>{{ item.LAST_STOP_DATE }}</span></div>
        </div>
      </div>
    </div>
    </van-list>
  </div>
</template>

<script>
import { Toast } from 'vant'
import { morningDayArrearDetail } from '@/api/publicline/board.js'

export default {
  data() {
    return {
      btnList: [
        { label: '全部', value: '' },
        { label: '开机', value: '5' },
        { label: '单向停机', value: '1' },
        { label: '双向停机', value: '2' },
        { label: '拆机', value: '3' }
      ],
      activeBtn: '',
      queryParams: {
        userStatus: '',
        deviceNum: '',
        pageNum: 1,
        pageSize: 15
      },
      loading: false,
      finished: false,
      dayId: '',
      levelId: '',
      list: []
    };
  },
  created() {
    this.levelId = this.$route.query.levelId;
    this.dayId = this.$route.query.dayId;
    this.loadData()
  },
  beforeDestroy() {
    Toast.clear()
  },
  methods: {
    async loadData(force) {
      // 改变搜索条件，重新查询
      if ( force ) {
        this.queryParams.pageNum = 1
        this.list = []
        this.finished = false
      }
      this.loading = true
      const res = await morningDayArrearDetail({ ...this.queryParams, levelId: this.levelId, dayId: this.dayId })
      const { result, success } = res
      if(success) {
        this.loading = false
        if(result.list.length < this.queryParams.pageSize) {
          this.finished = true
          Toast({
            message: '已全部加载',
            duration: 500,
            position: 'bottom',
            forbidClick: 'true'
          });
        }
        this.list = this.list.concat(result.list)
        Toast.clear()
      }
    },
    onload() {
      this.loading = false
      if(this.finished === false) {
        Toast({
          type:'loading',
          duration: 0,
          message: '正在加载',
          position: 'bottom',
          forbidClick: 'true'
        })
        this.queryParams.pageNum = parseInt(this.queryParams.pageNum) + 1
        this.loadData()
      } else {
        Toast({
          message: '已全部加载',
          duration: 500,
          position: 'bottom',
          forbidClick: 'true'
        })
      }
    },
    handleSearch(val) {
      this.queryParams.deviceNum = val
      this.loadData(true)
    },
    hadleBtn(val) {
      this.queryParams.userStatus = val
      this.loadData(true)
    }
  }
}
</script>

<style lang="less" scoped>
@import '~@/assets/less/person.less';
.search-group {
  margin-bottom: 8px;
  padding-left: 8px;
  background: #fff;
  .van-search__content {
    padding-left: 8px;
    background-color: unset;
    border-radius: unset;
    border-bottom: 1px solid #ddd;
  }
  .van-field {
    width: 60%;
    /deep/ .van-field__left-icon {
      color: #999;
    }
  }
  .btn-search {
    padding-left: 10px;
    padding-bottom: 10px;
    padding-top: 2px;
  }
  .btn-item {
    margin-right: 4px;
    cursor: pointer;
    &.active {
      color: #4D98FF;
    }
    &:last-child {
      margin-right: 0;
    }
  }
}
.detail-info {
  .info-detail {
    display: flex;
    align-items: center;
  }
  .info-tc {
    flex-wrap: wrap;
  }
  .info-desc {
    width: 50%;
    > span {
      padding-left: 12px;
    }
  }
}
</style>